package com.mes.system.manager;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.mes.common.manager.BasicManager;
import com.mes.system.manager.iface.ISysOperationAuthManager;
import com.mes.system.dao.SysOperationAuthDao;
import com.mes.system.domain.SysOperationAuth;

@Component
public class SysOperationAuthManager extends BasicManager<SysOperationAuth> implements ISysOperationAuthManager {
	
	public static final Log log = LogFactory
			.getLog(SysOperationAuthManager.class);
	
	@Autowired
	private SysOperationAuthDao sysOperationAuthDao;
	
	/**
	 * todo 暂时没有考虑黑白名单 将来应该考虑做成spring拦截器
	 */
	@Override
	public void validOperationAuth(String sysOperationUid, String operatorUid)
			throws Exception {
		// 如果都没有，证明没有限制
		log.info("*************checking validation!******************");
		List<SysOperationAuth> authList = this.sysOperationAuthDao
				.getAuthListByOperationUid(sysOperationUid);
		if (authList == null || authList.isEmpty())
			return;

		for (SysOperationAuth auth : authList) {
			if (auth.getEmployeeUid() != null
					&& auth.getEmployeeUid().equals(operatorUid)) {
				return;
			}
		}
		throw new Exception("对不起，您无权进行此操作！");
	}
}
